package com.single.weblearn.dao;

import java.util.List;

import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

import com.single.weblearn.meta.Account;
import com.single.weblearn.typehandler.BigInToDoubleHandler;

public interface AccountDao {
	@Results({ @Result(property = "id", column = "id"), 
		@Result(property = "title", column = "title"),
			@Result(property = "buyPrice", column = "buyprice",jdbcType=JdbcType.BIGINT,javaType=Double.class,typeHandler = BigInToDoubleHandler.class),			
			@Result(property = "buyNum", column = "buyNum"), @Result(property = "buyTime", column = "buyTime"),
			@Result(property = "total", column = "total",jdbcType=JdbcType.BIGINT,javaType=Double.class, typeHandler = BigInToDoubleHandler.class) })
	@Select({"SELECT content.id as id,"
			+ "content.title as title,"
			+ "content.icon as image,"
			+ "trx.price as buyprice,"
			+ "sum(CASE WHEN trx.contentId is not null and trx.personId=0  THEN 1 ELSE 0 END) as buynum,"
			+ "trx.time as buytime,"
			+ "sum(CASE WHEN trx.price is not null and trx.personId=0  THEN trx.price ELSE 0 END) as total"
			+ " FROM content LEFT JOIN trx on content.id=trx.contentId where trx.personId=0 group by buytime"})
	public List<Account> getbuylist();
}
